package cn.sm1234.serverlet;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;

// 过滤器
@WebFilter(filterName = "helloFilter", urlPatterns = "/helloServlet")  // 这里拦截了/helloServlet
public class HelloFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void destroy() {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("执行了前面代码");
        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println("执行了后面代码");
    }
}
